<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>Paho C++: src/mqtt/thread_queue.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="pahologo.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">Paho C++
   &#160;<span id="projectnumber">1.0</span>
   </div>
   <div id="projectbrief">The Paho MQTT C++ Client Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('thread__queue_8h_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Friends</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">thread_queue.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="thread__queue_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment">/*******************************************************************************</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> * Copyright (c) 2017 Frank Pagliughi &lt;fpagliughi@mindspring.com&gt;</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment"> * All rights reserved. This program and the accompanying materials</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment"> * are made available under the terms of the Eclipse Public License v1.0</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"> * and Eclipse Distribution License v1.0 which accompany this distribution.</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="comment"> * The Eclipse Public License is available at</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="comment"> *    http://www.eclipse.org/legal/epl-v10.html</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="comment"> * and the Eclipse Distribution License is available at</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="comment"> *   http://www.eclipse.org/org/documents/edl-v10.php.</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="comment"> * Contributors:</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="comment"> *    Frank Pagliughi - initial implementation and documentation</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="comment"> *******************************************************************************/</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="preprocessor">#ifndef __mqtt_thread_queue_h</span></div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="preprocessor"></span><span class="preprocessor">#define __mqtt_thread_queue_h</span></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="preprocessor"></span></div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="preprocessor">#include &lt;thread&gt;</span></div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;<span class="preprocessor">#include &lt;mutex&gt;</span></div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<span class="preprocessor">#include &lt;condition_variable&gt;</span></div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="preprocessor">#include &lt;limits&gt;</span></div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;<span class="preprocessor">#include &lt;deque&gt;</span></div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;<span class="preprocessor">#include &lt;queue&gt;</span></div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;<span class="keyword">namespace </span>mqtt {</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T, <span class="keyword">class</span> Container=std::deque&lt;T&gt;&gt;</div>
<div class="line"><a name="l00067"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html">   67</a></span>&#160;<span class="keyword">class </span><a class="code" href="classmqtt_1_1thread__queue.html">thread_queue</a></div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;{</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00071"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#a3541d204c67e24f64b70f26d721bc032">   71</a></span>&#160;    <span class="keyword">using</span> <a class="code" href="classmqtt_1_1thread__queue.html#a3541d204c67e24f64b70f26d721bc032">container_type</a> = Container;</div>
<div class="line"><a name="l00073"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#a03ec540c315e1284e9df8fe1db9e0837">   73</a></span>&#160;    <span class="keyword">using</span> <a class="code" href="classmqtt_1_1thread__queue.html#a03ec540c315e1284e9df8fe1db9e0837">value_type</a> = T;</div>
<div class="line"><a name="l00075"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#a0258577b49c271d5b330ed81f2d596d6">   75</a></span>&#160;    <span class="keyword">using</span> <a class="code" href="classmqtt_1_1thread__queue.html#a0258577b49c271d5b330ed81f2d596d6">size_type</a> = <span class="keyword">typename</span> Container::size_type;</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;</div>
<div class="line"><a name="l00078"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#a5c0a3b1044293fddcd6d100c39069a26">   78</a></span>&#160;    <span class="keyword">static</span> constexpr <a class="code" href="classmqtt_1_1thread__queue.html#a0258577b49c271d5b330ed81f2d596d6">size_type</a> <a class="code" href="classmqtt_1_1thread__queue.html#a5c0a3b1044293fddcd6d100c39069a26">MAX_CAPACITY</a> = std::numeric_limits&lt;size_type&gt;::max();</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;    <span class="keyword">mutable</span> std::mutex lock_;</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;    std::condition_variable notEmptyCond_;</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;    std::condition_variable notFullCond_;</div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;    <a class="code" href="classmqtt_1_1thread__queue.html#a0258577b49c271d5b330ed81f2d596d6">size_type</a> cap_;</div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;    std::queue&lt;T,Container&gt; que_;</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;    <span class="keyword">using</span> guard = std::lock_guard&lt;std::mutex&gt;;</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;    <span class="keyword">using</span> unique_guard = std::unique_lock&lt;std::mutex&gt;;</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00101"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#a69e67e267fb59e0c2902e476a3456e1f">  101</a></span>&#160;    <a class="code" href="classmqtt_1_1thread__queue.html#a69e67e267fb59e0c2902e476a3456e1f">thread_queue</a>() : cap_(<a class="code" href="classmqtt_1_1thread__queue.html#a5c0a3b1044293fddcd6d100c39069a26">MAX_CAPACITY</a>) {}</div>
<div class="line"><a name="l00107"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#ae134cc86ccf92a9b1a7843fec5ffc189">  107</a></span>&#160;    <span class="keyword">explicit</span> <a class="code" href="classmqtt_1_1thread__queue.html#ae134cc86ccf92a9b1a7843fec5ffc189">thread_queue</a>(<span class="keywordtype">size_t</span> cap) : cap_(cap) {}</div>
<div class="line"><a name="l00113"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#a26821f9803dd991601ceac9d6043cef9">  113</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classmqtt_1_1thread__queue.html#a26821f9803dd991601ceac9d6043cef9">empty</a>()<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;        guard g(lock_);</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;        <span class="keywordflow">return</span> que_.empty();</div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;    }</div>
<div class="line"><a name="l00121"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#a4c51ca4923aac7765dbf5639afb5dd5a">  121</a></span>&#160;    <a class="code" href="classmqtt_1_1thread__queue.html#a0258577b49c271d5b330ed81f2d596d6">size_type</a> <a class="code" href="classmqtt_1_1thread__queue.html#a4c51ca4923aac7765dbf5639afb5dd5a">capacity</a>()<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;        guard g(lock_);</div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;        <span class="keywordflow">return</span> cap_;</div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;    }</div>
<div class="line"><a name="l00131"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#a1a3d5689a5c9de91df58f08751a9a151">  131</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="classmqtt_1_1thread__queue.html#a1a3d5689a5c9de91df58f08751a9a151">capacity</a>(<a class="code" href="classmqtt_1_1thread__queue.html#a0258577b49c271d5b330ed81f2d596d6">size_type</a> cap) {</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;        guard g(lock_);</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;        cap_ = cap;</div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;    }</div>
<div class="line"><a name="l00139"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#a6f23c815b33be58b2ac2a6aba159108d">  139</a></span>&#160;    <a class="code" href="classmqtt_1_1thread__queue.html#a0258577b49c271d5b330ed81f2d596d6">size_type</a> <a class="code" href="classmqtt_1_1thread__queue.html#a6f23c815b33be58b2ac2a6aba159108d">size</a>()<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;        guard g(lock_);</div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;        <span class="keywordflow">return</span> que_.size();</div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;    }</div>
<div class="line"><a name="l00149"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#af480a8f58a85ac1456232dcbe88b43a0">  149</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="classmqtt_1_1thread__queue.html#af480a8f58a85ac1456232dcbe88b43a0">put</a>(<a class="code" href="classmqtt_1_1thread__queue.html#a03ec540c315e1284e9df8fe1db9e0837">value_type</a> val) {</div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;        unique_guard g(lock_);</div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;        <a class="code" href="classmqtt_1_1thread__queue.html#a0258577b49c271d5b330ed81f2d596d6">size_type</a> n = que_.size();</div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;        <span class="keywordflow">if</span> (n &gt;= cap_)</div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;            notFullCond_.wait(g, [=]{<span class="keywordflow">return</span> que_.size() &lt; cap_;});</div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;        que_.emplace(std::move(val));</div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;        <span class="keywordflow">if</span> (n == 0) {</div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;            g.unlock();</div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;            notEmptyCond_.notify_one();</div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;        }</div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;    }</div>
<div class="line"><a name="l00166"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#a422932e446605d6df9cad670a3d5f795">  166</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classmqtt_1_1thread__queue.html#a422932e446605d6df9cad670a3d5f795">try_put</a>(<a class="code" href="classmqtt_1_1thread__queue.html#a03ec540c315e1284e9df8fe1db9e0837">value_type</a> val) {</div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;        unique_guard g(lock_);</div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;        <a class="code" href="classmqtt_1_1thread__queue.html#a0258577b49c271d5b330ed81f2d596d6">size_type</a> n = que_.size();</div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;        <span class="keywordflow">if</span> (n &gt;= cap_)</div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;            <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;        que_.emplace(std::move(val));</div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;        <span class="keywordflow">if</span> (n == 0) {</div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;            g.unlock();</div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;            notEmptyCond_.notify_one();</div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;        }</div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;    }</div>
<div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;    <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Rep, <span class="keyword">class</span> Period&gt;</div>
<div class="line"><a name="l00187"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#ab0c10d47c27bd0acfd61dd9172f807de">  187</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classmqtt_1_1thread__queue.html#ab0c10d47c27bd0acfd61dd9172f807de">try_put_for</a>(<a class="code" href="classmqtt_1_1thread__queue.html#a03ec540c315e1284e9df8fe1db9e0837">value_type</a>* val, <span class="keyword">const</span> std::chrono::duration&lt;Rep, Period&gt;&amp; relTime) {</div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;        unique_guard g(lock_);</div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;        <a class="code" href="classmqtt_1_1thread__queue.html#a0258577b49c271d5b330ed81f2d596d6">size_type</a> n = que_.size();</div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;        <span class="keywordflow">if</span> (n &gt;= cap_ &amp;&amp; !notFullCond_.wait_for(g, relTime, [=]{<span class="keywordflow">return</span> que_.size() &lt; cap_;}))</div>
<div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;            <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;        que_.emplace(std::move(val));</div>
<div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;        <span class="keywordflow">if</span> (n == 0) {</div>
<div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;            g.unlock();</div>
<div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;            notEmptyCond_.notify_one();</div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;        }</div>
<div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;    }</div>
<div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;    <span class="keyword">template</span> &lt;<span class="keyword">class</span> Clock, <span class="keyword">class</span> Duration&gt;</div>
<div class="line"><a name="l00210"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#ab7086ef1aff63b6f6bc905a4653f33b5">  210</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classmqtt_1_1thread__queue.html#ab7086ef1aff63b6f6bc905a4653f33b5">try_put_until</a>(<a class="code" href="classmqtt_1_1thread__queue.html#a03ec540c315e1284e9df8fe1db9e0837">value_type</a>* val, <span class="keyword">const</span> std::chrono::time_point&lt;Clock,Duration&gt;&amp; absTime) {</div>
<div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;        unique_guard g(lock_);</div>
<div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;        <a class="code" href="classmqtt_1_1thread__queue.html#a0258577b49c271d5b330ed81f2d596d6">size_type</a> n = que_.size();</div>
<div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;        <span class="keywordflow">if</span> (n &gt;= cap_ &amp;&amp; !notFullCond_.wait_until(g, absTime, [=]{<span class="keywordflow">return</span> que_.size() &lt; cap_;}))</div>
<div class="line"><a name="l00214"></a><span class="lineno">  214</span>&#160;            <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00215"></a><span class="lineno">  215</span>&#160;        que_.emplace(std::move(val));</div>
<div class="line"><a name="l00216"></a><span class="lineno">  216</span>&#160;        <span class="keywordflow">if</span> (n == 0) {</div>
<div class="line"><a name="l00217"></a><span class="lineno">  217</span>&#160;            g.unlock();</div>
<div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;            notEmptyCond_.notify_one();</div>
<div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;        }</div>
<div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;    }</div>
<div class="line"><a name="l00228"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#ab10061c6d4eeefa9d6e3002fc2eea6c3">  228</a></span>&#160;    <span class="keywordtype">void</span> <span class="keyword">get</span>(<a class="code" href="classmqtt_1_1thread__queue.html#a03ec540c315e1284e9df8fe1db9e0837">value_type</a>* val) {</div>
<div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;        unique_guard g(lock_);</div>
<div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;        <span class="keyword">auto</span> n = que_.size();</div>
<div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;        <span class="keywordflow">if</span> (n == 0)</div>
<div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;            notEmptyCond_.wait(g, [=]{<span class="keywordflow">return</span> !que_.empty();});</div>
<div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;        *val = std::move(que_.front());</div>
<div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;        que_.pop();</div>
<div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;        <span class="keywordflow">if</span> (n == cap_) {</div>
<div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;            g.unlock();</div>
<div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;            notFullCond_.notify_one();</div>
<div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;        }</div>
<div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160;    }</div>
<div class="line"><a name="l00246"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#af86a422283cfc8c6b95098dcbc495533">  246</a></span>&#160;    <a class="code" href="classmqtt_1_1thread__queue.html#a03ec540c315e1284e9df8fe1db9e0837">value_type</a> <span class="keyword">get</span>() {</div>
<div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160;        unique_guard g(lock_);</div>
<div class="line"><a name="l00248"></a><span class="lineno">  248</span>&#160;        <span class="keyword">auto</span> n = que_.size();</div>
<div class="line"><a name="l00249"></a><span class="lineno">  249</span>&#160;        <span class="keywordflow">if</span> (n == 0)</div>
<div class="line"><a name="l00250"></a><span class="lineno">  250</span>&#160;            notEmptyCond_.wait(g, [=]{<span class="keywordflow">return</span> !que_.empty();});</div>
<div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;        <a class="code" href="classmqtt_1_1thread__queue.html#a03ec540c315e1284e9df8fe1db9e0837">value_type</a> val = std::move(que_.front());</div>
<div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;        que_.pop();</div>
<div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;        <span class="keywordflow">if</span> (n == cap_) {</div>
<div class="line"><a name="l00254"></a><span class="lineno">  254</span>&#160;            g.unlock();</div>
<div class="line"><a name="l00255"></a><span class="lineno">  255</span>&#160;            notFullCond_.notify_one();</div>
<div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;        }</div>
<div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;        <span class="keywordflow">return</span> val;</div>
<div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;    }</div>
<div class="line"><a name="l00267"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#a696a704cfcf4333390ee632bc4e069c9">  267</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classmqtt_1_1thread__queue.html#a696a704cfcf4333390ee632bc4e069c9">try_get</a>(<a class="code" href="classmqtt_1_1thread__queue.html#a03ec540c315e1284e9df8fe1db9e0837">value_type</a>* val) {</div>
<div class="line"><a name="l00268"></a><span class="lineno">  268</span>&#160;        unique_guard g(lock_);</div>
<div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;        <span class="keyword">auto</span> n = que_.size();</div>
<div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;        <span class="keywordflow">if</span> (n == 0)</div>
<div class="line"><a name="l00271"></a><span class="lineno">  271</span>&#160;            <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00272"></a><span class="lineno">  272</span>&#160;        *val = std::move(que_.front());</div>
<div class="line"><a name="l00273"></a><span class="lineno">  273</span>&#160;        que_.pop();</div>
<div class="line"><a name="l00274"></a><span class="lineno">  274</span>&#160;        <span class="keywordflow">if</span> (n == cap_) {</div>
<div class="line"><a name="l00275"></a><span class="lineno">  275</span>&#160;            g.unlock();</div>
<div class="line"><a name="l00276"></a><span class="lineno">  276</span>&#160;            notFullCond_.notify_one();</div>
<div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;        }</div>
<div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;    }</div>
<div class="line"><a name="l00290"></a><span class="lineno">  290</span>&#160;    <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Rep, <span class="keyword">class</span> Period&gt;</div>
<div class="line"><a name="l00291"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#a4f762168e9543c7f3988c5a41d4c921b">  291</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classmqtt_1_1thread__queue.html#a4f762168e9543c7f3988c5a41d4c921b">try_get_for</a>(<a class="code" href="classmqtt_1_1thread__queue.html#a03ec540c315e1284e9df8fe1db9e0837">value_type</a>* val, <span class="keyword">const</span> std::chrono::duration&lt;Rep, Period&gt;&amp; relTime) {</div>
<div class="line"><a name="l00292"></a><span class="lineno">  292</span>&#160;        unique_guard g(lock_);</div>
<div class="line"><a name="l00293"></a><span class="lineno">  293</span>&#160;        <span class="keyword">auto</span> n = que_.size();</div>
<div class="line"><a name="l00294"></a><span class="lineno">  294</span>&#160;        <span class="keywordflow">if</span> (n == 0 &amp;&amp; !notEmptyCond_.wait_for(g, relTime, [=]{<span class="keywordflow">return</span> !que_.empty();}))</div>
<div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160;            <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00296"></a><span class="lineno">  296</span>&#160;        *val = std::move(que_.front());</div>
<div class="line"><a name="l00297"></a><span class="lineno">  297</span>&#160;        que_.pop();</div>
<div class="line"><a name="l00298"></a><span class="lineno">  298</span>&#160;        <span class="keywordflow">if</span> (n == cap_) {</div>
<div class="line"><a name="l00299"></a><span class="lineno">  299</span>&#160;            g.unlock();</div>
<div class="line"><a name="l00300"></a><span class="lineno">  300</span>&#160;            notFullCond_.notify_one();</div>
<div class="line"><a name="l00301"></a><span class="lineno">  301</span>&#160;        }</div>
<div class="line"><a name="l00302"></a><span class="lineno">  302</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00303"></a><span class="lineno">  303</span>&#160;    }</div>
<div class="line"><a name="l00314"></a><span class="lineno">  314</span>&#160;    <span class="keyword">template</span> &lt;<span class="keyword">class</span> Clock, <span class="keyword">class</span> Duration&gt;</div>
<div class="line"><a name="l00315"></a><span class="lineno"><a class="line" href="classmqtt_1_1thread__queue.html#af8d9ff987f6b59b070c7da4e3867cacb">  315</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classmqtt_1_1thread__queue.html#af8d9ff987f6b59b070c7da4e3867cacb">try_get_until</a>(<a class="code" href="classmqtt_1_1thread__queue.html#a03ec540c315e1284e9df8fe1db9e0837">value_type</a>* val, <span class="keyword">const</span> std::chrono::time_point&lt;Clock,Duration&gt;&amp; absTime) {</div>
<div class="line"><a name="l00316"></a><span class="lineno">  316</span>&#160;        unique_guard g(lock_);</div>
<div class="line"><a name="l00317"></a><span class="lineno">  317</span>&#160;        <span class="keyword">auto</span> n = que_.size();</div>
<div class="line"><a name="l00318"></a><span class="lineno">  318</span>&#160;        <span class="keywordflow">if</span> (n == 0 &amp;&amp; !notEmptyCond_.wait_until(g, absTime, [=]{<span class="keywordflow">return</span> !que_.empty();}))</div>
<div class="line"><a name="l00319"></a><span class="lineno">  319</span>&#160;            <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00320"></a><span class="lineno">  320</span>&#160;        *val = std::move(que_.front());</div>
<div class="line"><a name="l00321"></a><span class="lineno">  321</span>&#160;        que_.pop();</div>
<div class="line"><a name="l00322"></a><span class="lineno">  322</span>&#160;        <span class="keywordflow">if</span> (n == cap_) {</div>
<div class="line"><a name="l00323"></a><span class="lineno">  323</span>&#160;            g.unlock();</div>
<div class="line"><a name="l00324"></a><span class="lineno">  324</span>&#160;            notFullCond_.notify_one();</div>
<div class="line"><a name="l00325"></a><span class="lineno">  325</span>&#160;        }</div>
<div class="line"><a name="l00326"></a><span class="lineno">  326</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00327"></a><span class="lineno">  327</span>&#160;    }</div>
<div class="line"><a name="l00328"></a><span class="lineno">  328</span>&#160;};</div>
<div class="line"><a name="l00329"></a><span class="lineno">  329</span>&#160;</div>
<div class="line"><a name="l00331"></a><span class="lineno">  331</span>&#160;<span class="comment">// end namespace mqtt</span></div>
<div class="line"><a name="l00332"></a><span class="lineno">  332</span>&#160;}</div>
<div class="line"><a name="l00333"></a><span class="lineno">  333</span>&#160;</div>
<div class="line"><a name="l00334"></a><span class="lineno">  334</span>&#160;<span class="preprocessor">#endif      // __mqtt_thread_queue_h</span></div>
<div class="line"><a name="l00335"></a><span class="lineno">  335</span>&#160;<span class="preprocessor"></span></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_a6f23c815b33be58b2ac2a6aba159108d"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#a6f23c815b33be58b2ac2a6aba159108d">mqtt::thread_queue::size</a></div><div class="ttdeci">size_type size() const </div><div class="ttdoc">Gets the number of items in the queue. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:139</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_a1a3d5689a5c9de91df58f08751a9a151"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#a1a3d5689a5c9de91df58f08751a9a151">mqtt::thread_queue::capacity</a></div><div class="ttdeci">void capacity(size_type cap)</div><div class="ttdoc">Sets the capacity of the queue. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:131</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_ae134cc86ccf92a9b1a7843fec5ffc189"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#ae134cc86ccf92a9b1a7843fec5ffc189">mqtt::thread_queue::thread_queue</a></div><div class="ttdeci">thread_queue(size_t cap)</div><div class="ttdoc">Constructs a queue with the specified capacity. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:107</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_ab7086ef1aff63b6f6bc905a4653f33b5"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#ab7086ef1aff63b6f6bc905a4653f33b5">mqtt::thread_queue::try_put_until</a></div><div class="ttdeci">bool try_put_until(value_type *val, const std::chrono::time_point&lt; Clock, Duration &gt; &amp;absTime)</div><div class="ttdoc">Attempt to place an item in the queue with a bounded wait to an absolute time point. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:210</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_a696a704cfcf4333390ee632bc4e069c9"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#a696a704cfcf4333390ee632bc4e069c9">mqtt::thread_queue::try_get</a></div><div class="ttdeci">bool try_get(value_type *val)</div><div class="ttdoc">Attempts to remove a value from the queue without blocking. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:267</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_af8d9ff987f6b59b070c7da4e3867cacb"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#af8d9ff987f6b59b070c7da4e3867cacb">mqtt::thread_queue::try_get_until</a></div><div class="ttdeci">bool try_get_until(value_type *val, const std::chrono::time_point&lt; Clock, Duration &gt; &amp;absTime)</div><div class="ttdoc">Attempt to remove an item from the queue for a bounded amout of time. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:315</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_a3541d204c67e24f64b70f26d721bc032"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#a3541d204c67e24f64b70f26d721bc032">mqtt::thread_queue::container_type</a></div><div class="ttdeci">Container container_type</div><div class="ttdoc">The underlying container type to use for the queue. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:71</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_a5c0a3b1044293fddcd6d100c39069a26"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#a5c0a3b1044293fddcd6d100c39069a26">mqtt::thread_queue::MAX_CAPACITY</a></div><div class="ttdeci">static constexpr size_type MAX_CAPACITY</div><div class="ttdoc">The maximum capacity of the queue. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:78</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_a0258577b49c271d5b330ed81f2d596d6"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#a0258577b49c271d5b330ed81f2d596d6">mqtt::thread_queue::size_type</a></div><div class="ttdeci">typename Container::size_type size_type</div><div class="ttdoc">The type used to specify number of items in the container. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:75</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_a69e67e267fb59e0c2902e476a3456e1f"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#a69e67e267fb59e0c2902e476a3456e1f">mqtt::thread_queue::thread_queue</a></div><div class="ttdeci">thread_queue()</div><div class="ttdoc">Constructs a queue with the maximum capacity. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:101</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html"><div class="ttname"><a href="classmqtt_1_1thread__queue.html">mqtt::thread_queue</a></div><div class="ttdoc">A thread-safe queue for inter-thread communication. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:67</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_a4c51ca4923aac7765dbf5639afb5dd5a"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#a4c51ca4923aac7765dbf5639afb5dd5a">mqtt::thread_queue::capacity</a></div><div class="ttdeci">size_type capacity() const </div><div class="ttdoc">Gets the capacity of the queue. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:121</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_a26821f9803dd991601ceac9d6043cef9"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#a26821f9803dd991601ceac9d6043cef9">mqtt::thread_queue::empty</a></div><div class="ttdeci">bool empty() const </div><div class="ttdoc">Determine if the queue is empty. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:113</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_a422932e446605d6df9cad670a3d5f795"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#a422932e446605d6df9cad670a3d5f795">mqtt::thread_queue::try_put</a></div><div class="ttdeci">bool try_put(value_type val)</div><div class="ttdoc">Non-blocking attempt to place an item into the queue. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:166</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_af480a8f58a85ac1456232dcbe88b43a0"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#af480a8f58a85ac1456232dcbe88b43a0">mqtt::thread_queue::put</a></div><div class="ttdeci">void put(value_type val)</div><div class="ttdoc">Put an item into the queue. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:149</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_ab0c10d47c27bd0acfd61dd9172f807de"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#ab0c10d47c27bd0acfd61dd9172f807de">mqtt::thread_queue::try_put_for</a></div><div class="ttdeci">bool try_put_for(value_type *val, const std::chrono::duration&lt; Rep, Period &gt; &amp;relTime)</div><div class="ttdoc">Attempt to place an item in the queue with a bounded wait. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:187</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_a4f762168e9543c7f3988c5a41d4c921b"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#a4f762168e9543c7f3988c5a41d4c921b">mqtt::thread_queue::try_get_for</a></div><div class="ttdeci">bool try_get_for(value_type *val, const std::chrono::duration&lt; Rep, Period &gt; &amp;relTime)</div><div class="ttdoc">Attempt to remove an item from the queue for a bounded amout of time. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:291</div></div>
<div class="ttc" id="classmqtt_1_1thread__queue_html_a03ec540c315e1284e9df8fe1db9e0837"><div class="ttname"><a href="classmqtt_1_1thread__queue.html#a03ec540c315e1284e9df8fe1db9e0837">mqtt::thread_queue::value_type</a></div><div class="ttdeci">T value_type</div><div class="ttdoc">The type of items to be held in the queue. </div><div class="ttdef"><b>Definition:</b> thread_queue.h:73</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_503ebd9f384f44c9859dcb1451d026bc.html">mqtt</a></li><li class="navelem"><a class="el" href="thread__queue_8h.html">thread_queue.h</a></li>
    <li class="footer">Generated on Sun Jul 23 2017 10:24:29 for Paho C++ by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6 </li>
  </ul>
</div>
</body>
</html>
